package stream;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * 寻找流中第一个元素
 */
public class StreamFind {
    public static void main(String[] args) {
        findFirst();
    }

    private static void findFirst() {
        List<Integer> list = Arrays.asList(1, 2, 3, 4);
        Optional<Integer> first = list.stream().findFirst();
//        Optional<Integer> first = list.stream().findAny(); // 和findFirst效果一样
        Integer i = first.get();
        System.out.println("i = " + i);
    }
}
